package com.rdc.qingkou.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/**
 * Created by asus on 2017/8/5.
 */

public class RectImageView extends AppCompatImageView {
    private float radiusX;
    private float radiusY;
    public RectImageView(Context context) {
        super(context);
        init();
    }

    public RectImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RectImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }



    private void init() {
        radiusX = 20;
        radiusY = 20;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Path path = new Path();
        Rect rect = new Rect(0, 0, getWidth(), getHeight());
        RectF rectF = new RectF(rect);
        path.addRoundRect(rectF, radiusX, radiusY, Path.Direction.CCW);

        canvas.clipPath(path, Region.Op.REPLACE);
        super.onDraw(canvas);
    }
}
